package com.gandong8.derby.core.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.gandong8.derby.core.constant.DOConstant;
import lombok.Data;

import java.io.Serializable;

@Data
public class ResponseData implements Serializable {
    private static final long serialVersionUID = 6045180599358894070L;
    private Integer code;
    private Object data;
    private String msg;
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Integer count;

    public ResponseData() {
    }

    public ResponseData(Integer code, Object data, String msg) {
        this.code = code;
        this.data = data;
        this.msg = msg;
    }

    public ResponseData(Integer code, Object data, String msg,Integer count) {
        this.code = code;
        this.data = data;
        this.msg = msg;
        this.count = count;
    }

    public static ResponseData succ() {
        return new ResponseData(DOConstant.Response.CODE_SUCC, null, DOConstant.Response.MSG_SUCC);
    }

    public static ResponseData succPage(Object data, Integer count) {
        return new ResponseData(DOConstant.Response.CODE_SUCC, data, DOConstant.Response.MSG_SUCC, count);
    }

    public static ResponseData succ(Object data) {
        return new ResponseData(DOConstant.Response.CODE_SUCC, data, DOConstant.Response.MSG_SUCC);
    }
    public static ResponseData succ(Object data, String msg) {
        return new ResponseData(DOConstant.Response.CODE_SUCC, data, msg);
    }

    public static ResponseData succ(Object data, Integer code) {
        return new ResponseData(code, data, null);
    }

    public static ResponseData fail() {
        return new ResponseData(DOConstant.Response.CODE_FAIL, null, DOConstant.Response.MSG_FAIL);
    }

    public static ResponseData login() {
        return new ResponseData(DOConstant.Response.CODE_LOGIN, null, DOConstant.Response.MSG_LOGIN);
    }

    public static ResponseData fail(String msg) {
        return new ResponseData(DOConstant.Response.CODE_FAIL, null, msg);
    }

    public static ResponseData fail(String msg, Integer code) {
        return new ResponseData(code, null, msg);
    }




    @Override
    public String toString() {
        return "ResponseData [code=" + code + ", data=" + data + ", msg=" + msg + "]";
    }

}

